
#ifndef __SCP_RECEIVE_CHANNEL_H
#define __SCP_RECEIVE_CHANNEL_H

#include "../aprtools/APRBucketBrigade.h"
#include "../aprtools/APRFuture.h"
#include "SSHChannel.h"

/** Class encapsulating a secure file transfer remote->local through
 * an SSH channel. */
class SCPReceiveChannel : public SSHChannel
{
   public:
      LIBSSH2_CHANNEL *initialiseSCPReceive(const char *remotefile, int64_t *remotefilelength, int *remoteaccess);
      SCPReceiveChannel(SSHClient &itclient);
      virtual ~SCPReceiveChannel();
      int getFileFromRemoteFile(LIBSSH2_CHANNEL *tchannel, const char *remotefile, int64_t remotefilelength, int remoteaccess,
         const char *localfile);
      char *getBufferFromRemoteFile(LIBSSH2_CHANNEL *tchannel, const char *remotefile, int64_t remotefilelength, int remoteaccess,
         int64_t *localbufferlen);
      APRFuture<int> *getFileFromRemoteFileFuture(const char *remotefile, const char *localfile, int remoteaccess);
      APRFuture<char *> *getBufferFromRemoteFileFuture(const char *remotefile, int64_t *localbufferlen, int remoteaccess);
      static void *getFileFromRemoteFileThread(apr_thread_t *tthread, void *args);
      static void *getBufferFromRemoteFileThread(apr_thread_t *tthread, void *args);
   protected:
      /** Enables access to getBufferFromRemoteFile from a thread.
       * 
       * @return Functor to getBufferFromRemoteFileThread. */
      virtual functor getGetBufferFromRemoteFileThread() const { return (functor)(&getBufferFromRemoteFileThread); }
      /** Enables access to getFileFromRemoteFile from a thread.
       * 
       * @return Functor to getFileFromRemoteFileThread. */
      virtual functor getGetFileFromRemoteFileThread() const { return (functor)(&getFileFromRemoteFileThread); }
};

#endif
